@extends('index.layouts.app')

@section('header')
    <link href="{{ asset('/font-awesome/css/font-awesome.min.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('/admin/layui/css/layui.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('/css/index/master.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('/css/index/gloable.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('/css/index/nprogress.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('/css/index/blog.css') }}" rel="stylesheet" type="text/css">
    <link href="{{ asset('/css/autocomplate.css') }}" rel="stylesheet" type="text/css">
    <style>
        .card-min-height{
            height: 220px;
            overflow: hidden;
            padding: 8px 4px;
        }
        .layui-col-md2-5{
            width: 20%;
        }
        .layui-carousel[lay-anim=updown]>[carousel-item]>*, .layui-carousel[lay-anim=fade]>[carousel-item]>* {
            left: 5px!important;
            top: 10px!important;
        }

        .layui-carousel .layui-carousel-ind {
            position: absolute;
            top: -41px;
            right: 51px;
            text-align: right;
        }
        .layui-card {
            margin-bottom: 0px;
        }
        .colum-height{
            height: 190px;
        }
        .card-style{
            margin: 4px;
            border-radius: 10px;
            height: 195px;
            box-shadow: 8px 10px  rgba(60,67,82,0.15);
            padding: 3px 3px 0 3px;
        }
        .layui-card-header {
            position: relative;
            height: 60px;
            line-height: 60px;
            padding: 0 0px;
            border-bottom: 1px solid #f6f6f6;
            color: #333;
            border-radius: 2px 2px 0 0;
            font-size: 14px;
            top: 5px;
        }
        .layui-nav {
            position: relative;
            padding: 0 20px;
            background-color: #fff;
            color: #555;
            border-radius: 2px;
            font-size: 0;
            box-sizing: border-box;
        }
    </style>
@endsection
@section('content')
    <div class="doc-container" id="doc-container">
        <div class="container-fixed" style="width:100%">
            <div class="col-content" style="width:100%">
                <div class="inner">

                    <div class="layui-fluid">
                        <div class="layui-card">
                            <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="margin-left: 15px;">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
{{--                                        <div class="layui-input-inline lay-search">--}}
{{--                                            <select name="stock" lay-verify="required" id="select_stock">--}}
{{--                                                @foreach($list as $key => $val)--}}
{{--                                                    <option @if($request->stock == $key) selected @endif value="{{$key}}">{{$val}}</option>--}}
{{--                                                @endforeach--}}
{{--                                            </select>--}}
{{--                                        </div>--}}
                                        <div class="layui-input-inline lay-search">
                                            <input type="text" name="number" id="qaTags" autocomplete="off" class="layui-input" placeholder="查询">


                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-search">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                        </button>
                                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-reset">
                                            <i class="layui-icon layuiadmin-button-btn">重置</i>
                                        </button>
                                    </div>
                                </div>
                            </div>


                            <div class="layui-card-body">
                                <div style="padding-bottom: 10px;">

                                </div>

                                <table id="LAY-form" lay-filter="LAY-form"></table>
                                <script type="text/html" id="ywy">
                                    <div><a target="_blank" href="/stock_forum_info?url=@{{d.url}}">@{{d.title}}</a></div>
                                </script>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

@endsection
@section('scripts')
    <script src="{{ asset('/admin/layui/layui.js') }}"></script>
    <script src="{{ asset('/js/index/gloable.js') }}"></script>
    <script src="{{ asset('/js/index/nprogress.js') }}"></script>
    <script src="{{ asset('/js/index/pagecomment.js') }}"></script>
    <script src="{{ asset('/js/jquery.min.js') }}"></script>
    <script src="{{ asset('/js/index/autocomplete.js') }}"></script>
    <script>NProgress.start();</script>
    <script>
        window.onload = function () {
            NProgress.done();
        };
    </script>
    <script type="text/javascript">
        var countries = [];
        $.ajax({
            type : 'get',
            url :  '/get_stock_all',
            dataType : "json",//json格式
            async : false,
            success : function(obj) {//成功后拿到的data
                var data = obj.data

                //循环放在对象
                for(var i=0;i<data.length;i++) {
                    var person = {};
                    person.value = data[i].stock_name + '/'  + data[i].stock_number;
                    person.data= data[i].stock_number;
                    countries.push(person);
                }
            }
        });
        $('#qaTags').autocomplete({
            lookup: countries,
            onSelect: function (suggestion) {
                 //console.log($("#qaTags").val());
                //点击触发调用
            }
        });
    </script>
    <script>
        layui.config({
            base: '../admin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form'], function(){
            var $ = layui.$
                ,form = layui.form
                ,table = layui.table
                ,views = layui.view;


            var layArray = new Array($,form,table,views)
            /**
             * 表格列表
             */
            var cols = [[
                {
                    type: "checkbox",
                    fixed: "left"
                },
                {
                    type: "numbers",
                    width: 100,
                    title: "ID"
                },
                {
                    field: "pls",
                    width: 100,
                    title: "评论数"
                },
                {
                    field: "title",
                    title: "原网页",
                    templet: "#ywy"
                },
                {
                    field: "date",
                    title: "创建时间",
                    sort: !0,
                },
            ]];

            var ele = "#LAY-form";
            var ajax_url = "get_stock_forum";
            var where = {stock: $("#select_stock").find("option:selected").val()};
            var initTable = Common.initTable(layArray,ele,ajax_url,cols,'',where);

            /**
             * 监听搜索
             */
            form.on('submit(LAY-search)', function(data){
                Common.search(data,1);
            });

        });//use

    </script>

    <script>
        var ele = 'LAY-form';
        var Common = function () {
            var initTable = function (layArray, ele, url, cols, doneCallBack, request) {
                var table = layArray[2];
                return table.render({
                    elem: ele
                    , url: url
                    , method: 'get'
                    , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                    , cols: cols
                    , page: !0
                    ,limit: 15
                    ,limits: [1, 10, 15, 20]
                    ,where:request
                    ,even: true //开启隔行背景
                    ,text: {
                        none: '暂无相关数据', //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                    }
                    ,autoSort: false //禁用前端自动排序。注意：该参数为 layui 2.4.4 新增
                    ,request: {
                        pageName: 'page',
                        limitName: 'perPage',
                    }
                    ,parseData: function(res){ //res 即为原始返回的数据
                        if(res.type == 1){
                            return {
                                "code": res.code, //解析接口状态
                                "count": "", //解析数据长度
                                "data": res.data //解析数据列表
                            };
                        }
                        return {
                            "code": res.code, //解析接口状态
                            "count": res.data.total, //解析数据长度
                            "data": res.data.data //解析数据列表
                        };
                    }
                    ,done: function (res, curr, count) {
                        if (typeof(doneCallBack) === "function") {
                            doneCallBack(res);
                        }
                    }
                });
            };

            var search = function (data,type) {
                if(type == 2){
                    data.field = '';
                }
                var field = data.field;
                //执行重载
                layui.table.reload(ele, {
                    where: field,
                    page:{curr:1}
                });
            }



            //返回
            var successReturn = function (data, index) {
                layer.msg(data.message, {
                    icon: 1
                    ,time: 2000
                },function () {
                    layui.table.reload('LAY-form'); //数据刷新
                    layer.close(index); //关闭弹层
                });
            }

            var errorReturn = function (data) {
                layer.msg(data.message, {
                    icon: 2
                    ,time: 2000
                },function () {

                });
            }

            var systemReturn = function (data) {
                layer.msg(data, {
                    icon: 3
                    ,time: 2000
                },function () {

                });
            }

            return {
                initTable: function (ele, url, cols, table, doneCallBack, request) {
                    return initTable(ele, url, cols, table, doneCallBack, request);
                },
                search: function (data,type) {
                    return search(data,type);
                },
                successReturn: function (data, index) {
                    return successReturn(data, index);
                },
                errorReturn: function (data) {
                    return errorReturn(data);
                },
                systemReturn: function (data) {
                    return systemReturn(data);
                }
            }
        }();
    </script>
@stop
